<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            // 构造函数
            function Person(name, age) {
                this.name = name;
                this.age = age;
            }
            let person1 = new Person('zs', 18);
            console.log(person1);

            function newObj(Func, ...args) {
                // 创建一个空对象
                let obj = {};
                // 将空对象的__proto__指向构造函数的原型对象
                obj.__proto__ == Func.prototype;
                let result = Func.apply(obj, args);
                return result instanceof Object ? result : obj;
            }
            // console.log(newObj(Person, 'zs', 30));
            let person2 = newObj(Person, 'zs', 19);
            console.log(person2);
        </script>
    </body>
</html>
